<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<html>
<head lang="en">    
   <meta charset="UTF-8">
   <title>登录</title>
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <meta name="format-detection" content="telephone=no">
   <meta name="renderer" content="webkit">
   <meta http-equiv="Cache-Control" content="no-siteapp"/>
   <link rel="stylesheet" th:href="@{css/main.css}"/>
    <link rel="stylesheet" th:href="@{css/amazeui.min.css}"/>

    <script th:src="@{/js/jquery-2.1.3.min.js}"></script>
    <script th:src="@{/js/amazeui.min.js}"></script>
    <script th:src="@{/js/sweet-alert.min.js}"></script>
</head>
<body>
   <div id="login">
       <h1>登录</h1>
       <form>
           <label>用户名
               <input type="text" class="input_text" id="nickName" required="required" placeholder="登录名"/>
           </label>
           <label for="password">密码
               <input type="password" class="input_text" id="password" required="required" placeholder="密码"/>
           </label>
           <input type="button" id="login_btn" class="am-btn am-btn-primary but" value="登录"/>
           <a href="create">去注册</a>
       </form>
   </div>  
</body>
<script>

$("#login_btn").on('click', function (e) {
    var nickName = $("#nickName").val();
    if (!nickName) {
        swal("缺少参数", "请填写登录名!", "error");
        return;
    }
    var password = $("#password").val();
    if (!password) {
        swal("缺少参数", "请填写密码!", "error");
        return;
    }
    $.ajax({
        url: "/users/login",
        data: {
            nickName: nickName,
            password: password
        },
        type: "POST",
        beforeSend: function (XHR) {
            $.AMUI.progress.start();
        },
        complete: function () {
            $.AMUI.progress.done();
        },
        success: function (result) {
            // alert(result);
            // var resultJson = JSON.parse(result);
            if (result.respCode == "1000") {
                swal("恭喜!", result.respMsg, "success");
                window.location.href="index?url="+result.url;
            } else {
                swal("抱歉!", result.respMsg, "error");
            }

        },
        error: function (xmlHttpReq, error, ex) {
            swal("发生了一些问题", xmlHttpReq.responseJSON.error, "error");
        }
    });
})
</script>
</html>  

